<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>签到登记管理</title>
	<meta name="decorator" content="ani"/>
	<style>
		.select-disabled {
			pointer-events: none;
			background-color: #eeeeee;
		}
	</style>
	<script type="text/javascript">

		$(document).ready(function() {

			$("#inputForm").find("select").each(function () {
				if ($(this).attr("data-value") != '' && $(this).attr("data-value") != undefined) {
					$(this).val($(this).attr("data-value"));
				}
			});

			jp.ajaxForm("#inputForm",function(data){
				if(data.success){
				    jp.success(data.msg);
					jp.go("${ctx}/buzz/sign/sign");
				}else{
				    jp.error(data.msg);
				    $("#inputForm").find("button:submit").button("reset");
				}
			});

		});

		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}

		$('#begindate').datetimepicker({
			format: "YYYY-MM-DD"
		});


		function selectRow() {
			var roomid = $("#room").val();
			if(roomid == "" || roomid == undefined){
				jp.error("请先选择教室！");
				return false;
			}

			if(roomid != '' && roomid != undefined){
				top.layer.open({
					type: 2,
					//shade:0,
					area: ['1300px', '1000px'],
					title:"选择",
					auto:true,
					maxmin: true, //开启最大化最小化按钮
					content: "${ctx}/buzz/sign/sign/outSelect?roomid="+roomid,
					btn: ['确定', '关闭'],
					yes: function(index, layero){
						var ids = layero.find("iframe")[0].contentWindow.getIdSelections();
						var data = layero.find("iframe")[0].contentWindow.getSelections();
						if(ids.length ==0){
							jp.warning("请选择至少一个数据!");
							return;
						}
						// 执行保存
						for(var i = 0;i<data.length; i++){
							addRow('#signentryList', signentryRowIdx, signentryTpl,data[i]);
							signentryRowIdx = signentryRowIdx + 1;
						}
						top.layer.close(index);
					},
					cancel: function(index){
						//取消默认为空，如需要请自行扩展。
						top.layer.close(index);
					}
				});
			}else {
				jp.error("请先选择教室");
			}

		}
	</script>
</head>
<body>
<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">
						<a class="panelButton" href="${ctx}/buzz/sign/sign"><i class="ti-angle-left"></i> 返回</a>
					</h3>
				</div>
				<div class="panel-body">
					<form:form id="inputForm" modelAttribute="sign" action="${ctx}/buzz/sign/sign/save" method="post" class="form-horizontal">
						<form:hidden path="id"/>
						<form:hidden path="classid"/>
						<form:hidden path="company.id"/>
						<form:hidden path="reguser.id"/>
						<fieldset class="well-new">
							<legend><i style="padding: 0px 5px 0px 5px" aria-hidden="true"></i>基本信息</legend>
							<div class="form-group">
								<label class="col-sm-2 col-md-1 control-label">登记人：</label>
								<div class="col-sm-10 col-md-2">
									<form:input path="reguser.name" htmlEscape="false"  readonly="true"  class="form-control "/>
								</div>
								<label class="col-sm-2 col-md-1 control-label">教室名称：</label>
								<div class="col-sm-10 col-md-2">
									<select id="room" name="room.id" class="form-control m-b required" data-value="${sign.room.id}">
										<option value=""></option>
										<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|教室管理' )}" var="dict">
											<option value="${dict.id}">${dict.name}</option>
										</c:forEach>
									</select>
								</div>
								<label class="col-sm-2 col-md-1 control-label">签到日期：</label>
								<div class="col-sm-10 col-md-2">
									<div class='input-group form_datetime' id='dataxs'>
										<input type='text' name="begindate" class="form-control " readonly="readonly"  value="<fmt:formatDate value="${sign.begindate}" pattern="yyyy-MM-dd"/>"/>
										<span class="input-group-addon">
											<span class="glyphicon glyphicon-calendar"></span>
										</span>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 col-md-1 control-label">备注：</label>
								<div class="col-sm-10 col-md-11">
									<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
								</div>
							</div>
						</fieldset>
						<div class="tabs-container">
							<ul class="nav nav-tabs">
								<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">签到明细：</a>
								</li>
							</ul>
						<div class="tab-content">
							<div id="tab-1" class="tab-pane fade in  active">
								<a class="btn btn-white btn-sm" onclick="selectRow()" title="添加"><i class="fa fa-plus"></i> 学生选择</a>
									<table class="table table-striped table-bordered table-condensed">
										<thead>
											<tr>
												<th class="hide"></th>
												<th>学生</th>
												<th>备注</th>
												<th width="10">&nbsp;</th>
											</tr>
										</thead>
										<tbody id="signentryList">
										</tbody>
									</table>
									<script type="text/template" id="signentryTpl">//<!--
										<tr id="signentryList{{idx}}">
											<td class="hide">
												<input id="signentryList{{idx}}_id" name="signentryList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
												<input id="signentryList{{idx}}_delFlag" name="signentryList[{{idx}}].delFlag" type="hidden" value="0"/>
											</td>
											<td>
												<input id="signentryList{{idx}}_studentid" 	 name="signentryList[{{idx}}].student.id" 	type="hidden" 	 value="{{row.student.id}}"    class="form-control "/>
												<input id="signentryList{{idx}}_studentname" name="signentryList[{{idx}}].student.name" readonly="true"	 value="{{row.student.name}}"    class="form-control "/>
											</td>
											<td>
												<input id="signentryList{{idx}}_remarks" name="signentryList[{{idx}}].remarks" type="text" value="{{row.remarks}}"    class="form-control "/>
											</td>
											<td class="text-center" width="10">
												{{#delBtn}}<span class="close" onclick="delRow(this, '#signentryList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
											</td>
										</tr>//-->
									</script>
									<script type="text/javascript">
										var signentryRowIdx = 0, signentryTpl = $("#signentryTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
										$(document).ready(function() {
											var data = ${fns:toJson(sign.signentryList)};
											for (var i=0; i<data.length; i++){
												addRow('#signentryList', signentryRowIdx, signentryTpl, data[i]);
												signentryRowIdx = signentryRowIdx + 1;
											}
										});
									</script>
							</div>
						</div>
						<fieldset>
							<legend><i style="padding: 0px 5px 0px 5px" class="fa fa-hand-o-right" aria-hidden="true"></i>附件信息</legend>
							<div class="form-group">
								<label class="col-sm-2 col-md-1 control-label">附件上传：</label>
								<div class="col-sm-10 col-md-11">
									<sys:fileUploadXD path="adjunctFileList" value="${fns:toJson(sign.adjunctFileList)}"/>
								</div>
							</div>
						</fieldset>
					</div>
					<c:if test="${mode == 'add' || mode=='edit'}">
							<div class="col-lg-3"></div>
							<div class="col-lg-6">
								 <div class="form-group text-center">
									 <div>
										 <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
									 </div>
								 </div>
							</div>
					</c:if>
					</form:form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>
